package com.dc.bobaoge.project.base.core.util;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * AdvertisementCommonUtil
 *
 * @author chenxueli
 * @date 2024-01-19 10:49:00
 */
public class AdvertisementCommonUtil {

    public static class DefaultChannel {

        // 广告区域与频道对应关系
        public static final HashMap<Integer, Long> CHANNEL_MOLD_TYPE_MAP = new HashMap<>() {{
            put(1, 1L);
            put(2, 2L);
            put(3, 8L);
            put(4, 3L);
            put(5, 4L);
            put(6, 5L);
            put(7, 6L);
            put(8, 7L);
        }};
        private static final List<Item> LIST = new ArrayList<>();
        private final static HashMap<Long, Item> MAP = new HashMap<>();

        static {
            LIST.add(new Item(1L, "主页"));
            LIST.add(new Item(2L, "爆款街"));
            LIST.add(new Item(3L, "招聘街"));
            LIST.add(new Item(4L, "品牌街"));
            LIST.add(new Item(5L, "失物招领"));
            LIST.add(new Item(6L, "本地大牌"));
            LIST.add(new Item(7L, "原料街"));
            LIST.add(new Item(8L, "拼手气"));

            // 执行map化
            LIST.forEach(item -> {
                MAP.put(item.getChannelId(), item);
            });
        }

        /**
         * 获取频道
         *
         * @param moldId 区域id
         * @return 频道名称
         */
        public static Item getChannelByMoldId(Integer moldId) {
            var channelId = CHANNEL_MOLD_TYPE_MAP.get(moldId);
            return getChannelByChannelId(channelId);
        }

        /**
         * 获取频道
         *
         * @param channelId 频道id
         * @return 频道
         */
        public static Item getChannelByChannelId(Integer channelId) {
            return getChannelByChannelId(channelId.longValue());
        }

        /**
         * 获取频道
         *
         * @param channelId 频道id
         * @return 频道
         */
        public static Item getChannelByChannelId(Long channelId) {
            return MAP.get(channelId);
        }

        @Getter
        @AllArgsConstructor
        public static class Item {

            /**
             * 频道id
             */
            private Long channelId;

            /**
             * 频道名称
             */
            private String channelName;

        }

    }

}
